#ifndef DATAFINDER_H
#define DATAFINDER_H

#include <QDir>
#include <QFileInfo>
#include <iostream>

#define DATA(n) Util::DataFinder::getInstance().getData(n)

namespace Util{

    class DataFinder{
    public:
        static const DataFinder & getInstance() {
            if(_singleton == 0) _singleton = new DataFinder();
            return *_singleton;
        }

        /// return true if the data directory exists
        bool dataDirExists() const { return datadir.exists(); }
        /// return the absolute path of the data directory
        QString getDataPath() const { return datadir.absolutePath(); }
        /// return true if the specified file exists in the data directory
        bool dataExists(const QString & fname) const { return datadir.exists(fname); }
        /// return the absolute file path of the specified file (if the file exists) or an empty string (if not)
        QString getData(const QString &fname) const {
            if(dataExists(fname)){
                return datadir.absoluteFilePath(fname);
            }else{
                std::cout << "Data file '" << datadir.absolutePath().toStdString() << "/" << fname.toStdString() << "' was not found !" << std::endl;
                return "";
            }
        }
    private:
        DataFinder():datadir("../data/") {}

        QDir datadir;
        static DataFinder * _singleton;
    };

}

#endif // DATAFINDER_H
